using System;
using MetaObjects.Contracts;
using Microsoft.SharePoint;

namespace MetaObjects.SharePoint
{
	public class FieldDateTime : FieldBase<SPFieldDateTime, DateTime?>
	{
		public SPDateTimeFieldFormatType DisplayFormat { get; set; }

		public FieldDateTime() { }

		public FieldDateTime(SPFieldDateTime field) : base(field)
		{
			DisplayFormat = field.DisplayFormat;
		}

		public override Action<SPListItem, DateTime?> SetField
		{
			get { return (item, value) => item[InternalName] = value; }
		}

		public override Func<SPListItem, DateTime?> GetField
		{
			get { return item => item[InternalName] as DateTime?; }
		}

		public override Func<SPFieldDateTime, IMetaField> FieldFactory
		{
			get { return f => new FieldDateTime(f); }
		}
	}
}